package com.project;

import com.project.servlet.AddServlet;
import com.project.servlet.JsonServlet;
import com.project.servlet.RegisterServlet;
import com.project.servlet.TestServlet;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.Wrapper;
import org.apache.catalina.startup.Tomcat;

public class MainBase {
    public MainBase(){
        Tomcat tomcat = new Tomcat();
        //设置启动端口
        tomcat.setPort(8088);
        //引导http引擎
        tomcat.getConnector();

        //得到上下文对象
        Context cxt = tomcat.addContext("",null);
        try {
            //注册servlet
            Wrapper w = Tomcat.addServlet(cxt,"testServlet",new TestServlet());
            //设置访问Servlet的URL路径
            w.addMapping("/zdy/*");

            //注册servlet
            Wrapper w1 = Tomcat.addServlet(cxt,"jsonServlet",new JsonServlet());
            //设置访问Servlet的URL路径
            w1.addMapping("/json");

            //注册servlet
            Wrapper w2 = Tomcat.addServlet(cxt,"addServlet",new AddServlet());
            //设置访问Servlet的URL路径
            w2.addMapping("/add");

            Wrapper w3 = Tomcat.addServlet(cxt,"register",new RegisterServlet());
            //设置访问Servlet的URL路径
            w3.addMapping("/reg");

            //启动tomcat
            tomcat.start();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        new MainBase();
    }
}
